#include<stdio.h>
int a,b,e,s[1000];
int main()
{
 // freopen("e.in","r",stdin);
  int i,t,j;
  scanf("%d%d",&a,&b);
  e=a+1;
  s[0]=1;t=0;
  for (i=1;i<=e;i++) 
    {
	  for (j=0;j<=t;j++)
	    s[j]=s[j]*2;
	  for (j=0;j<=t;j++)
	    if (s[j]>9)
	      {
		    s[j+1]+=s[j]/10;
			s[j]=s[j]%10;	
		  }
	  if (s[t+1]!=0) ++t; 
	}
  while (s[t]!=b && e<=62)
    {
	  for (j=0;j<=t;j++)
	    s[j]=s[j]*2;
	  for (j=0;j<=t;j++)
	    if (s[j]>9)
	      {
			s[j+1]+=s[j]/10;
			s[j]=s[j]%10;	
		  }
	  if (s[t+1]!=0) ++t;
	  ++e;
	}
  if (s[t]==b) printf("%d\n",e);else printf("0\n");
  return 0;
}